<template>
  <div>
    <el-card>
      <template #header>
        <div class="searchHead">
          <el-form :model="form" inline>
            <el-form-item label="企业名称:">
              <el-select
                v-model="form.keyWord"
                filterable
                clearable
                placeholder="请选择公司名称"
                @change="nameChange"
                style="width: 200px"
              >
                <el-option
                  v-for="item in options"
                  :key="item.enterpriseId"
                  :label="item.cmpName"
                  :value="item.enterpriseId"
                />
                <template #prefix>
                  <el-icon class="el-input__icon"><search /></el-icon>
                </template>
              </el-select>
            </el-form-item>
          </el-form>
        </div>
      </template>
      <el-table
        ref="enterpriseRef"
        :data="tableData"
        style="width: 100%; max-height: 61vh; height: 61vh"
        table-layout="fixed"
        v-loading="loading"
        :header-cell-style="{'text-align':'center'}"
        :cell-style="{'text-align':'center'}"
      >
        <el-table-column fixed min-width="120" prop="cmpName" label="企业名称" show-overflow-tooltip/>
        <el-table-column prop="energyConsumeLevel" label="能耗级别" />
        <el-table-column prop="enterpriseCode" label="统一社会信用代码" />
        <el-table-column prop="isorg" label="是否公共机构" />
        <el-table-column prop="corporationName" label="法人代表" />
        <el-table-column prop="registerPrincipal" label="注册资金(万元)" />
        <el-table-column prop="registerDate" label="注册日期" />
        <!--           <el-table-column prop="secretKey" label="工作密钥" />
          <el-table-column prop="dataIndex" label="是否注册" /> -->
        <el-table-column fixed="right" label="操作" width="160">
          <template #default="scope">
            <el-button
              link
              type="primary"
              @click="edit(scope.$index, scope.row)"
              >项目分析</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        layout="total, sizes, prev, pager, next, jumper"
        :page-sizes="[10,20,30,40,50,100,500]"
        background
        v-model:page-size="pagination.size"
        v-model:current-page="pagination.page"
        :total="pagination.total"
        @size-change="sizeChange"
        @current-change="pageChange"
        class="pagination"
      />
    </el-card>
  </div>
</template>

<script setup>
import { reactive, ref, defineEmits } from "vue";
import { enterNamePageList,getNameList } from "@/api/enterprise";
import { ElMessage } from "element-plus";
import mitts from "@/utils/bus.js";

const pagination = reactive({
  page: 1,
  size: 10,
  total: 0,
});
const options = ref([]);
const condition = ref([]);
const loading = ref(true);
const tableData = ref([]);
const propForId = ref("");
const form = reactive({
  cmpName: "",
});
const nameChange = (value) => {
  let cond = [];
  let temp = {};
  if (value != "" && value != undefined) {
    temp = {
      column: "enterpriseId",
      type: "eq",
      value: value,
    };
    cond.push(temp);
  }

  condition.value = cond;
  doDataList();
};
const sizeChange = (value) => {
  pagination.size = value;
  pagination.page = 1;
  doDataList();
};
/**
 * 页总数改变
 */
const pageChange = (value) => {
  pagination.page = value;
  doDataList();
};
const edit = (index, rowData) => {
  propForId.value = rowData.enterpriseId;
  mitts.emit("enterpriseId", rowData.enterpriseId);
  mitts.emit("isShow",true);
  mitts.emit("enterpriseCode",rowData.enterpriseCode);
};
const doDataList = () => {
  loading.value = true;
  let datas = {
    pageNum: pagination.page,
    pageSize: pagination.size,
    condition: JSON.stringify(condition.value),
  };

  enterNamePageList(datas)
    .then((res) => {
      //获取到信息
      tableData.value = res.data.records;
      pagination.size = res.data.pageSize;
      pagination.page = res.data.currentPage;
      pagination.total = res.data.total;
      //请求完成,开始处理数据
      
      loading.value = false;
    })
    .catch((msg) => {
      //获取出错
      ElMessage.error("获取信息失败，请联系管理员！");
    });
    getNameList().then((res)=>{
      options.value = res.data;
    }).catch((msg) =>{

    })
};
doDataList();
</script>

<style lang="less" scoped>
.title {
  min-width: 5em;
}
.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-light-9);
}
.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-light-9);
}
.el-card__header {
  max-height: 10vh;
}
.pagination {
  max-height: 3vh;
}
</style>
